Skip to content

[GR-55885] Initialize FileSystemProvider at run time (future defaults) #11205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented May 15, 2025

This changes allows initializing FileSystemProviders at image run time. Since that is a behavioral change, the functionality must be unlocked with --future-defaults=all or --future-defaults=run-time-initialized-jdk (see also #10531).

Note that with this turned on, no FileSystemProviders are allowed in the image heap. Since those are referenced from common JDK classes, like java.io.File or java.nio.Path, and these classes unfortunately often end up in static variables, we have special handling for those to allow them in the image heap. However, this is not the case for custom Path implementations. So the general advice is to ensure that Path and File objects are created at image run time.

It allows to do the following that was previously not possible:

public class Main {
    public static void main(String[] args) throws Exception {
        URI uri = URI.create("myfs:///");
        try (FileSystem fs = FileSystems.newFileSystem(uri, Map.of())) {
            Path path = fs.getPath("/test.txt");
            Files.write(path, "Hello from myfs!".getBytes(StandardCharsets.UTF_8));
            String content = Files.readString(path);
            System.out.println(content);
        }
    }
}

The example assumes that META-INF/services/java.nio.file.spi.FileSystemProvider contains a custom FileSystemProvider that registers the myfs scheme.

Fixes #5134

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label May 15, 2025
@zapster zapster marked this pull request as draft May 15, 2025 10:10
@zapster zapster self-assigned this May 15, 2025
@graalvmbot graalvmbot changed the title [WIP] [GR-55885] Initialize FileSystemProvider at run time [GR-55885] Initialize FileSystemProvider at run time May 27, 2025
@graalvmbot graalvmbot force-pushed the je/svm-file-system-provider-runtime-GR-55885 branch from af3312a to 4a71804 Compare May 28, 2025 14:11
@zapster zapster marked this pull request as ready for review May 28, 2025 14:26
@graalvmbot graalvmbot changed the title [GR-55885] Initialize FileSystemProvider at run time [GR-55885] Initialize FileSystemProvider at run time (future defaults) May 28, 2025
@graalvmbot graalvmbot force-pushed the je/svm-file-system-provider-runtime-GR-55885 branch from 4a71804 to 587d778 Compare May 30, 2025 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Providers loaded by FileSystemProvider not handled correctly in native image
2 participants